﻿using Microsoft.AspNetCore.Http;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace PowerStation.RequestModel
{
    /// <summary>
    /// 上传文件,接收base64数据
    /// </summary>
    public class RequestUploadFileBase64Model
    {
        /// <summary>
        /// 上传类型,监控截图,电站潮流图
        /// </summary>
        public string typeName { get; set; }
        /// <summary>
        /// 文件类型
        /// </summary>
        public string contentType { get; set; }
        /// <summary>
        /// 文件名称
        /// </summary>
        public string fileName { get; set; }
        /// <summary>
        /// 文件数据
        /// </summary>
        public string fileData { get; set; }
    }
    /// <summary>
    /// 模拟上个传文件
    /// </summary>
    public class RequestUploadFile : IFormFile
    {
        private MemoryStream ms;

        public RequestUploadFile(MemoryStream ms)
        {
            this.ms = ms;
        }

        public string ContentDisposition { get; set; }

        public string ContentType { get; set; }

        public string FileName { get; set; }

        public IHeaderDictionary Headers { get; set; }

        public long Length { get { return ms.Length; } }

        public string Name { get; set; }

        public void CopyTo(Stream target)
        {
            ms.CopyTo(target);
        }

        public Task CopyToAsync(Stream target, CancellationToken cancellationToken = default)
        {
            return ms.CopyToAsync(target,cancellationToken);
        }

        public Stream OpenReadStream()
        {
            return ms;
        }
    }
}
